package org.example.streaminterate;

import java.util.stream.Stream;

public class Java8StreamIterate1 {
    public static void main(String[] args) {
        Stream.iterate(0,n -> n + 1)
                .limit(10)
                .forEach(System.err::println);
        System.err.println("-------------------");
        Stream.iterate(0,n -> n + 1)
                .filter(x -> x % 2 != 0)
                .limit(10)
                .forEach(System.err::println);
        System.err.println("-------------------");
        Stream.iterate(new int[]{0,1},n -> new int[]{n[1],n[0] + n[1]})
                .limit(20)
                .map(n -> n[0])
                .forEach(System.err::println);
        System.err.println("-------------------");
        int sum = Stream.iterate(new int[]{1,1},n -> new int[]{n[1],n[0] + n[1]})
                .limit(10)
                .map(n -> n[0])
                .mapToInt(x -> x)
                .sum();
        System.err.println(sum);
    }
}
